package BLL.User;

import BIZ.statementofncomeBiz;
import BIZ.totalFeeBiz;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@WebServlet(name = "ConfirmRecharge", value = "/ConfirmRecharge")
public class ConfirmRecharge extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public ConfirmRecharge() {
        super();
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        HttpSession session = request.getSession();

        //获取表单递送的用户信息
        String money = new String(request.getParameter("money").getBytes(StandardCharsets.UTF_8));


        //从session获取信息
        String UserName = (String) session.getAttribute("UserName");
        String carid1 = (String) session.getAttribute("CaiNumber1");
        String carid2 = (String) session.getAttribute("CaiNumber2");
        String carid3 = (String) session.getAttribute("CaiNumber3");

        statementofncomeBiz statementofncomeBiz = new statementofncomeBiz();
        totalFeeBiz totalFeeBiz = new totalFeeBiz();

        //进行充值
        String newbalance = statementofncomeBiz.confirmcharge(UserName, money);

        //将充值的总数额递到total
        int x = totalFeeBiz.aadincome(money);

        //进行账单插入
        int addbill = statementofncomeBiz.addbill(UserName, carid1, carid2, carid3, money);

        //将充值后的余额存入session
        session.setAttribute("Balance", newbalance);


    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

}
